package jmine.tec.script.persistent;

import jmine.tec.script.ScriptDispatcher;
import jmine.tec.script.persistent.context.ScriptExecutionContextFactory;
import jmine.tec.script.persistent.domain.ScriptDependency;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

import bancosys.tec.persist.controller.AbstractPersistenceEnabledController;

/**
 * Controller do módulo de scripts persistentes.
 * 
 * @author lundberg
 */
public class ScriptController extends AbstractPersistenceEnabledController implements BeanFactoryAware {

    private ScriptExecutionContextFactory contextFactory;

    private ScriptDispatcher dispatcher;

    private BeanFactory beanFactory;

    /**
     * @return the contextFactory
     */
    public ScriptExecutionContextFactory getContextFactory() {
        return this.contextFactory;
    }

    /**
     * @return the dispatcher
     */
    public ScriptDispatcher getDispatcher() {
        return this.dispatcher;
    }

    /**
     * @param contextFactory the contextFactory to set
     */
    public void setContextFactory(ScriptExecutionContextFactory contextFactory) {
        this.contextFactory = contextFactory;
    }

    /**
     * @param dispatcher the dispatcher to set
     */
    public void setDispatcher(ScriptDispatcher dispatcher) {
        this.dispatcher = dispatcher;
    }

    /**
     * Busca uma dependência de um script
     * 
     * @param dependency dependency
     * @return Object
     */
    public Object findDependency(ScriptDependency dependency) {
        return this.beanFactory.getBean(dependency.getBean());
    }

    /**
     * {@inheritDoc}
     */
    public void setBeanFactory(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }
}
